package controllers;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.AutoSite;

import data.AutoSiteData;

public class DeleteSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		//Get siteId
		String siteId = (String) request.getParameter("siteId");
		//Get site info
		AutoSiteData aData = new AutoSiteData();
		AutoSite autoSite = aData.getById(siteId);
		if (autoSite != null) {
			aData.delete(autoSite);
			response.sendRedirect("/add-site?blogId=" + autoSite.getBlogId());
		} else {
			response.sendRedirect("/message?txt=page-not-found");
			return;
		}
	}
}
